package s14.ch16.ex3.homework;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

public class ReplaceInputFilter extends FilterInputStream {
	private Integer space;
	private Integer krecha;

	public ReplaceInputFilter(InputStream in, Integer space, Integer krecha) {
		super(in);
		setSpace(space);
		setKrecha(krecha);
	}

	public Integer getSpace() {
		return space;
	}

	public Integer getKrecha() {
		return krecha;
	}

	public int read() throws IOException {
		Integer read = super.read();
		if (read == -1) {
			return -1;
		}
		
		if (read == space) {
			read = krecha;
		}
		Integer result = read;
		return result;
	}

	public void setSpace(Integer space) {
		this.space = space;
	}

	public void setKrecha(Integer krecha) {
		this.krecha = krecha;
	}

}
